<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="author" content="Yb">
    <title>练习-对象的原型链继承</title>
    <style>
        
    </style>
</head>
<body>
    
</body>
</html>
<script>
    // 原型
    function People(name,age,isMale){
        this.name = name;
        this.age = age;
        this.isMale = isMale;
    }

    People.prototype.say = function(word){
        console.log(this.name + '说：“Hello！我是' + this.age +'岁的'+ word +'。”');
    }


    // 继承1、Boy对象
    function Boy(name,age,isMale){
        People.call(this,name,age,isMale);
    }
    function Temp(){};
    Temp.prototype = People.prototype;
    var Person = new Temp();
    Boy.prototype = Person;

    Boy.prototype.play = function(game,hours){
        console.log(this.name + '玩' + game + hours + '小时');
    }

    var Boy = new Boy('Tom',22,true);
    console.dir(Boy);
    console.log(Boy.name);
    console.log(Boy.age);
    console.log(Boy.isMale);

    Boy.say('男生');
    Boy.play('消消乐',2);


    // 继承2、Girl对象
    function Girl(name,age,isMale){
        People.call(this,name,age,isMale);
    }

    function Temp(){};
    Temp.prototype = People.prototype;
    var Person = new Temp();
    Girl.prototype = Person;

    Girl.prototype.goShopping = function(place,hours){
        console.log(this.name + '去' + place + '逛街' + hours + '小时');
    }

    var Girl = new Girl('Lily',20,false,true);
    Object.defineProperty(Girl,'isLongHair',{    
        value: true,
        writable: true,
        configurable: true,
        enumerable:false,
    });
    console.dir(Girl);
    console.log(Girl.name);
    console.log(Girl.age);
    console.log(Girl.isMale);
    console.dir(Girl.isLongHair);

    Girl.say('女生');
    Girl.goShopping('二七广场',3);





















</script>